#include <iostream>
using namespace std;
int n,a[2001],col[2001],ans=-1145;
int scr()
{
    int res=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i-1;j>0;j--)
            if(col[i]==col[j]&&a[i]==a[j])
            {
                res+=a[i];
                break;
            }
    }
    return res;
}
void dfs(int pos)
{
    if(pos==n+1)
    {
        ans=max(ans,scr());
        return;
    }
    col[pos]=1;
    dfs(pos+1);
    col[pos]=2;
    dfs(pos+1);
}
int main()
{
    ios::sync_with_stdio(0);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--)
    {
        ans=-1145;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        dfs(1);
        cout<<ans<<endl;
    }
    return 0;
}
